﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using YSC_Core.BLL.Domain.BackstageModels;
using YSC_Services.BLL.Services.Interfaces;

namespace YSC_Backstage_Web.Controllers
{
    /// <summary>
    /// 数据字典
    /// </summary>
    public class DictionaryController : Controller
    {
        private readonly IBasisBackstageServices _pro;
        public DictionaryController(IBasisBackstageServices pro)
        {
            _pro = pro;
        }
        //Dictionary
        //数字字典
        public IActionResult Index()
        {
            return View();
        }

        public JsonResult GetList(int limit, int page, string type)
        {
            var aa = _pro.GetDictionaryAll(page, limit, type);
            return Json(aa);
        }

        public IActionResult Add()
        {
            return View();
        }

        public IActionResult Edit(string Id)
        {
            ViewData["Id"] = Id;
            return View();
        }

        public JsonResult GetDictionaryById(string Id)
        {
            var dEntity = _pro.GetDictionary(Id);
            return Json(dEntity);
        }

        public JsonResult AddUpdateSubmit(string paramete)
        {
            var job = (JObject)JsonConvert.DeserializeObject(paramete);
            var dEntity = new DictionaryModels
            {
                Id = job["Id"].ToString(),
                Name = job["Name"].ToString(),
                Remarks = job["Remarks"].ToString(),
                Type = job["Type"].ToString()
            };
            var result = _pro.AddUpdateDictionary(dEntity);
            return Json(result);
        }

        public JsonResult GetDictionaryType(string type)
        {
            var result = _pro.GetDictionaryTypeAll();
            return Json(result);
        }

        public JsonResult DelSubmit(string Id)
        {
            var aa = _pro.DelectDictionary(Id);
            return Json(aa);
        }
    }
}